/*
 * File:   mem.h
 * Author: gustavo
 *
 * Created on August 17, 2011, 2:49 AM
 */

#ifndef MEM_H
#define	MEM_H

#ifdef	__cplusplus
extern "C" {
#endif

#include <stdlib.h>

#include "types.h"

#define mem_alloc_size(size) (void *) calloc( 1, (size) )
#define mem_alloc(type) (type *) calloc( 1, sizeof(type) )
#define mem_allocn(n, type) (type *) calloc( (n), sizeof(type) )
#define mem_free(p) { if(p) {free(p); p = NULL;} }
#define mem_copy( dest, src, n ) ( mem_copy_function( (char*) dest, (char*) src, n*sizeof(*src) ) )
#define mem_clear( src, n) ( mem_clear_function( (char*) src, n*sizeof(*src) ) )

	inline void mem_copy_function(char * dest, char * src, int nbytes);
	inline void mem_clear_function(char * dest, int nbytes);

	//void mem_copyi(int n, int * x, int incx, int * y, int incy);

	boolean mem_copyr(int n, real * dest, int incd, real * src, int incs);
	boolean mem_copymr(int m, int n, real * dest, int incd, real * src, int incs);

#ifdef	__cplusplus
}
#endif

#endif	/* MEM_H */

